package com.huang.design.proxy.cjlib;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import org.omg.PortableInterceptor.Interceptor;

import java.lang.reflect.Method;

public class eatProxy {

    public static<T> T getProxy(T t){
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(t.getClass());
        enhancer.setCallback(new MethodInterceptor() {
            @Override
            public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
                //执行代理对象的方法
                Object o1 = methodProxy.invokeSuper(o, objects);
                System.out.println("这是cglib代理逻辑。。。");
                return null;
            }
        });
        Object o = enhancer.create();
        return (T) o;
    }

}
